// app.js
import './utils/utils'
import './utils/http'
App({
  onLaunch() {
    this.getToken('token')
    this.getToken('refresh_token')
  },
  getToken(key) {
    wx.getStorage({
      key,
      success: (r) => {
        if (r.errMsg === 'getStorage:ok') {
          // this => App 实例对象
          this[key] = r.data
        }
      },
      fail(e) {
        // 如果获取不到信息会走这儿
        console.log(e)
      }
    })
  },
  setToken(token, refresh_token) {
    token = 'Bearer ' + token
    refresh_token = 'Bearer ' + refresh_token

    wx.setStorageSync('token', token)
    wx.setStorageSync('refresh_token', refresh_token)

    this.token = token
    this.refresh_token = refresh_token
  }
})